/***********************************************************************************
 *                                                                                 *
 * Voreen - The Volume Rendering Engine                                            *
 *                                                                                 *
 * Copyright (C) 2005-2012 University of Muenster, Germany.                        *
 * Visualization and Computer Graphics Group <http://viscg.uni-muenster.de>        *
 * For a list of authors please refer to the file "CREDITS.txt".                   *
 *                                                                                 *
 * This file is part of the Voreen software package. Voreen is free software:      *
 * you can redistribute it and/or modify it under the terms of the GNU General     *
 * Public License version 2 as published by the Free Software Foundation.          *
 *                                                                                 *
 * Voreen is distributed in the hope that it will be useful, but WITHOUT ANY       *
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR   *
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.      *
 *                                                                                 *
 * You should have received a copy of the GNU General Public License in the file   *
 * "LICENSE.txt" along with this file. If not, see <http://www.gnu.org/licenses/>. *
 *                                                                                 *
 * For non-commercial academic use see the license exception specified in the file *
 * "LICENSE-academic.txt". To get information about commercial licensing please    *
 * contact the authors.                                                            *
 *                                                                                 *
 ***********************************************************************************/

#ifndef VRN_STREAMLINETEXTUREADJ_H
#define VRN_STREAMLINETEXTUREADJ_H

#include "modules/flowreen/datastructures/simpletexture.h"

namespace voreen {

class Flow2D;
class Flow3D;

template<typename T>
class StreamlineTextureAdj : public SimpleTexture<T> {

using SimpleTexture<T>::data_;
using SimpleTexture<T>::autoFree_;
using SimpleTexture<T>::numElements_;
using SimpleTexture<T>::dimensions_;

public:
    struct StreamlineTextureElement {
        StreamlineTextureElement(T& elem, size_t& counter)
            : elem_(elem), counter_(counter)
        {}

        operator T() { return elem_; }

        T& elem_;
        size_t& counter_;
    };

public:
    StreamlineTextureAdj(const tgt::ivec2& dimensions, const bool autoFree = true);
    StreamlineTextureAdj(const tgt::ivec3& dimensions, const bool autoFree = true);
    virtual ~StreamlineTextureAdj();

    virtual void free();

    const typename StreamlineTextureAdj<T>::StreamlineTextureElement operator[](size_t index) const;
    const typename StreamlineTextureAdj<T>::StreamlineTextureElement operator[](const tgt::ivec2& position) const;
    const typename StreamlineTextureAdj<T>::StreamlineTextureElement operator[](const tgt::ivec3& position) const;

    typename StreamlineTextureAdj<T>::StreamlineTextureElement operator[](size_t index);
    typename StreamlineTextureAdj<T>::StreamlineTextureElement operator[](const tgt::ivec2& position);
    typename StreamlineTextureAdj<T>::StreamlineTextureElement operator[](const tgt::ivec3& position);

    static T* integrateDraw(const Flow2D& flow, const size_t textureScaling,
        const size_t sampling, const tgt::vec2& thresholds = tgt::vec2(0.0f));

    static T* integrateDraw(const Flow3D& flow, const size_t textureScaling,
        const size_t sampling, const tgt::vec2& thresholds = tgt::vec2(0.0f));

    static T* fastLIC(const Flow2D& flow, const SimpleTexture<float>& inputTexture,
        const size_t textureScaling, const size_t sampling, const int maxKernelSize,
        const tgt::vec2& threshold = tgt::vec2(0.0f), const bool useAdaptiveKernelSize = false);

    static T* multiLIC(const Flow2D& flow, const Flow2D& flow2, const SimpleTexture<float>& inputTexture,
        const size_t textureScaling, const size_t sampling, const int maxKernelSize,
        const tgt::vec2& threshold = tgt::vec2(0.0f), const bool useAdaptiveKernelSize = false);

private:
    // prevent objects of this class from being copied
    //
    StreamlineTextureAdj(const StreamlineTextureAdj&);
    StreamlineTextureAdj& operator=(const StreamlineTextureAdj&);

    static float fastLICIntensity(const SimpleTexture<float>& inputTexture,
        const int indexR0, const int kernelSize, const std::vector<tgt::ivec2>& streamline);

private:
    size_t* const counter_;
};

}   // namespace

#endif
